<template>
  <Back />
  <div class="page">
    <div class="flex justify-between tag">
      <div :class="{ active: type == 0 }" @click="getData(0)">{{ $t('prize.start') }}</div>
      <div :class="{ active: type == 1 }" @click="getData(1)">{{ $t('prize.end') }}</div>
    </div>

    <van-empty v-if="list.finished && list.data.length < 1" :description="$t('common.noData')" />
    <van-list
      v-if="!list.finished || list.data.length > 0"
      v-model:loading="list.loading"
      :finished="list.finished"
      @load="getList"
      :immediate-check="false"
    >
      <div v-for="item in list.data" :key="item.id" class="record">
        <div class="flex" @click="go('/prize?id=' + item.id)">
          <div>
            <img :src="item.icon" />
          </div>
          <div class="flex flex-col justify-between">
            <div class="font-size-16px">{{ item.title }}</div>
            <div>{{ item.endTime }}</div>
            <div>{{ $t('prize.people') }} {{ item.participants }}</div>
            <div>
              <van-button :disabled="type == 1" size="small" block type="primary" round>{{ $t('prize.join') }}</van-button>
            </div>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script setup lang="ts">
const router = useRouter()

// 0进行中 1已结束
const type = ref(0)

const { getList, list, reset } = useList(apis.api.userPrizePage, { type: type.value })

function go(path: string) {
  router.push(path)
}

const getData = (t: number) => {
  type.value = t
  reset()
  list.query.type = t
  getList()
}

onMounted(async () => {
  list.loading = true
  getList()
})
</script>

<style lang="scss" scoped>
.page {
  box-sizing: border-box;
  min-height: 100vh;
  background-color: #fafafa;
}
.record {
  margin: 16px 16px 0;
  background-color: #fff;
  border-radius: 4px;
  padding: 8px 8px;
  font-size: 14px;
  img {
    width: 100px;
    height: 100px;
    margin-right: 10px;
  }
}
.red {
  color: #fb553c;
}
.green {
  color: #3aa1a2;
}

.tag {
  padding: 16px;
  font-size: 14px;
  > div {
    text-align: center;
    border-radius: 5px;
    background-color: #dcdcdc;
    line-height: 40px;
    width: 46%;
  }
  .active {
    background-color: #3aa1a2;
    color: #fff;
  }
}
</style>
